<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/pages/inc/taglibs.jsp" %>
<%@ include file="/WEB-INF/pages/inc/nocache.jsp" %>
<%@ include file="/WEB-INF/pages/inc/meta.jsp" %>
<html>
<head>
    <title>库存修改</title>
    <script type="text/javascript" src="/js/jquery.js"></script>
    <script src="/js/jquery-validation/jquery.validate.js" type="text/javascript"></script>
    <script src="/js/jquery-validation/additional-methods.js" type="text/javascript"></script>
    <script src="/js/jquery-validation/messages_cn.js" type="text/javascript"></script>
    <script type="text/javascript">
        var checkFlg = false;
        $().ready(function() {
//            $("#editForm").validate({
//                rules: {
//                    userName: {
//                        required:true
//                    }
//                    ,
//                    realName:"required",
//                    email: {
//                        required: true,
//                        email: true
//                    },
//                    userPassword: {
//                        required: true,
//                        minlength: 6
//                    },
//                    confirmPassword: {
//                        required: true,
//                        minlength: 6,
//                        equalTo: "#userPassword"
//                    },
//                    groupNo:{
//                        required: true,
//                        minlength: 3,
//                        maxlength:3,
//                        digits:true
//                    } ,
//                    memberNo:{
//                        required: true,
//                        minlength: 2,
//                        maxlength:2 ,
//                        digits:true
//                    },
//                    phone:{
//                        minlength:11,
//                        maxlength:11,
//                        digits:true
//                    }
//                },
//                messages: {
//                    email: {
//                        email: "邮箱格式不正确"
//                    }
//                    ,
//                    userPassword: {
//                        minlength: jQuery.format("不能小于{0}个位")
//                    },
//                    confirmPassword: {
//                        minlength:jQuery.format("不能小于{0}个位"),
//                        equalTo: "两次输入密码不一致"
//                    } ,
//                    groupNo:{
//                        minlength: jQuery.format("不能小于{0}个位"),
//                        maxlength:jQuery.format("不能大于{0}个位"),
//                        digits:"格式不正确"
//                    } ,
//                    memberNo:{
//                        minlength: jQuery.format("不能小于{0}个位"),
//                        maxlength:jQuery.format("不能大于{0}个位"),
//                        digits:"格式不正确"
//                    },
//                    phone:{
//                        minlength:jQuery.format("不能小于{0}个位"),
//                        maxlength:jQuery.format("不能大于{0}个位"),
//                        digits:"格式不正确"
//                    }
//                }
//            });
            $("#productType").change(function(){
                  var $type = $(this);
                  var $brand = $("#productBrand");
                  var $model = $("#productModel");
                  $.get("/get/product/brand.aspx?r=" + Math.random(), {method:"getBrandOption",type:$type.val()}, function(data) {

                        $brand.html("<option value=''>==请选择==</option>");
                        $brand.append(data);
                        $model.html("<option value=''>==请选择==</option>");
                    });
            });
             $("#productBrand").change(function(){
                  var $type = $("#productType");
                  var $brand = $(this);
                  var $model = $("#productModel");
                  $.get("/get/product/model.aspx?r=" + Math.random(), {method:"getModelOption",type:$type.val(),brand:$brand.val()}, function(data) {
                        $model.html("<option value=''>==请选择==</option>");
                        $model.append(data);
                    });
            });

            $(".delProduct_button").live("click",function () {
                 var temp = '';
                 $(this).parent().children().each(function(i,n){
                     var txt = $.trim($(n).html());
                     if(txt !="删除")   temp = temp + txt+",";//弹出子元素标签
                 });
                  temp =  temp+ ";";
                  var products =  $("#products").val();
                  $("#products").val(products.replace(temp,''));
                  $(this).parent().html('');
             });
            $("#addProduct_button").click(function(){
                 var $type = $("#productType").val();
                 var $brand = $("#productBrand").val();
                 var $model = $("#productModel").val();
                 var $serialNo = $("#serialNo").val();
                 var $price = $("#price").val();

                 var product = $type+","+ $brand +","+$model +","+$serialNo +","+$price+"," ;
                 var $products = $("#products").val()  + product + ";";
                 $("#products").val($products);

                $("#product_tab").append("<tr>"+"<td>"+$type+"</td>"+"<td>"+$brand+"</td>"+"<td>"+$model+"</td>"+"<td>"+$serialNo+"</td>"+"<td>"+$price+"</td>"+"<td class='delProduct_button'>删除</td>"+"</tr>")   ;
            });
        })
    </script>
    <style type="text/css">
        #field, label {
            font-family: Arial, Helvetica, sans-serif;
            font-size: small;
        }

        input.submit {
            float: none;
        }

        label.error {
            padding-left: 5px;
            margin-left: .3em;
            color: red;
        }
    </style>

</head>
<body>
<div style="color: red;">${error}</div>
<form id="saveForm" action="${ctx}/stock/save.aspx" method="post">
    <input type="hidden" name="id" value="${entity.id}">
    <input type="text" id="products" name="products" value="">
    <table>
        <tr>
            <td align="right">库存流水：</td>
            <td><input type="text" id="stockNo" name="stockNo" value="${entity.stockNo}" size="25" readonly="readonly"></td>
        </tr>
        <tr>
            <td align="right">产品信息:

            </td>
            <td>
                <table id="product_tab">
                    <tbody>
                        <td>类型</td>
                        <td>品牌</td>
                        <td>型号</td>
                        <td>编号</td>
                        <td>价格</td>
                        <td>操作</td>
                    </tbody>
                    <tr id="tr1">
                         <div id="addProduct_div">
                           <c:forEach items="${entity.inProducts}" var="product">
                                <div>${product.productNo}</div>
                            </c:forEach>
                        </div>
                    </tr>
                    <tr id="tr2">
                         <td>
                         <select name="productType" id="productType">
                            <option value="">==请选择==</option>
                            <c:forEach items="${productTypeList}" var="productTypeName">
                                <option value="${productTypeName}" >
                                        ${productTypeName}
                                </option>
                            </c:forEach>
                        </select>
                         </td>
                        <td>
                             <select name="productBrand" id="productBrand" >
                                <option value="">==请选择==</option>
                                <c:forEach items="${productBrandList}" var="productBrandName">
                                    <option value="${productBrandName}" >
                                            ${productBrandName}
                                    </option>
                                </c:forEach>
                            </select>
                        </td>
                        <td>
                             <select name="productModel" id="productModel">
                                <option value="">==请选择==</option>
                                <c:forEach items="${productModelList}" var="productModelName">
                                    <option value="${productModelName}"　>
                                            ${productModelName}
                                    </option>
                                </c:forEach>
                            </select>
                        </td>
                        <td><input id="serialNo" type="text" value="" name="serialNo" style="width:80px;"></td>
                        <td><input id="price" type="text" value="" name="price" style="width:80px;"> </td>
                        <td><input id="addProduct_button" type="button" value="添加"><input id="clearProduct_button" type="button" value="清除">　</td>
                    </tr>
                </table>

        </tr> 
        <tr>
            <td></td>
            <td><input type="submit" value="提交"></td>
        </tr>
    </table>
</form>
</body>
</html>